# Contributor: omni <omni+alpine@hack.org>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=snowflake
pkgver=2.9.2
pkgrel=4
pkgdesc="Pluggable Transport for Tor using WebRTC, inspired by Flashproxy"
url="https://snowflake.torproject.org/"
license="BSD-3-Clause"
arch="all !riscv64" # ftbfs
makedepends="go"
options="!check" # no test files
subpackages="$pkgname-doc"
source="https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/archive/v$pkgver/snowflake-v$pkgver.tar.gz
	0001-fix-build-error-on-loongarch64_patch
	"
builddir="$srcdir/$pkgname-v$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	case "$CARCH" in
	loongarch64)
		patch -p1 -i "$srcdir"/0001-fix-build-error-on-loongarch64_patch
		;;
	esac
}

build() {
	cd "$builddir"/client
	go build -v .

	cd "$builddir"/proxy
	go build -v .
}

package() {
	install -Dm0755 client/client "$pkgdir"/usr/bin/"$pkgname"-client
	install -Dm0755 proxy/proxy "$pkgdir"/usr/bin/"$pkgname"-proxy
	install -Dm0644 doc/snowflake-*.1 -t "$pkgdir"/usr/share/man/man1
}

sha512sums="
bfae8be9f7696c5a77129b49e3f874b32ddb62ba82becaa805a9ad94c85b90494baab084f8df133e8d8bbdc21b2285d91df0f72ce1c988632a778ccbf77d1793  snowflake-v2.9.2.tar.gz
386b56dbd319a7937c15d22191e35132185e52a3a7544e4622439ad6928570d54f76519ac3d3e15a822a6cd5cb014768a23adb3dfc8eaac3e42cb0012a1e3bf9  0001-fix-build-error-on-loongarch64_patch
"
